package testing.cms.controller;
import testing.cms.manager.CmsManager;
import core.cms.model.Block;

import com.opensymphony.xwork2.ActionSupport;

public class CmsController extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 14343L;
	private String identifier ;
	private String content ;
	private Block block ;
	private Block block1 ;
	private CmsManager cmsmanager ;
	public CmsController()
	{
		cmsmanager =  new CmsManager();
	}
	public String execute() {
		this.identifier=this.getIdentifier();
		this.content=this.getContent();
		block1 = cmsmanager.getBlockByIdentifier(block.getIdentifier());
		this.block = this.getBlock();
		if(block1==null) {
			
		cmsmanager.addBlock(block);
		}
		else {
			cmsmanager.updateBlock(block.getContent(),block.getIdentifier());
		}
		return SUCCESS ;
	}
	public Block getBlock() {
		return block;
	}
	public void setBlock(Block block) {
		this.block = block;
	}
	public String getIdentifier() {
		return identifier;
	}
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String quote(String data)
	{
		String content = new String("");
		System.out.println(data + "this is done");
		Block blo =  cmsmanager.getBlockByIdentifier(data) ;
		if(blo != null)
		{
			content = blo.getContent();
		}
		return content ;
	}
}
